import { BaseSessionStorage } from '@lhy-assist/utils'
import * as names from './name'

// 当前登录用户
export const loginRespSession = new BaseSessionStorage<{ macKey: string }>({
  name: names.ADMIN_INFO,
}).extend({
  // 当前对象中是否有存储着正确的用户数据
  hasData: () => {
    const loginResp = loginRespSession.get()
    return !!(loginResp && loginResp.macKey)
  },
})

export const activeMenuSession = new BaseSessionStorage<{ defaultActive: string; defaultOpeneds: string[] }>({
  name: names.ACTIVE_MENU,
}).extend({
  getData: () => {
    return (
      activeMenuSession.get() || {
        defaultActive: '',
        defaultOpeneds: [],
      }
    )
  },
})
